home *** CD-ROM | disk | FTP | other *** search
- package java.beans;
-
- import java.util.Hashtable;
-
- public class PropertyEditorManager {
- private static String[] searchPath = new String[]{"sun.beans.editors"};
- private static Hashtable registry;
-
- public static PropertyEditor findEditor(Class targetType) {
- initialize();
- Class editorClass = (Class)registry.get(targetType);
- if (editorClass != null) {
- try {
- Object o = editorClass.newInstance();
- return (PropertyEditor)o;
- } catch (Exception var7) {
- System.err.println("Couldn't instantiate type editor \"" + editorClass.getName() + "\" : " + var7);
- }
- }
-
- String editorName = targetType.getName() + "Editor";
-
- try {
- return instantiate(targetType, editorName);
- } catch (Exception var6) {
- for(editorName = targetType.getName(); editorName.indexOf(46) > 0; editorName = editorName.substring(editorName.indexOf(46) + 1)) {
- }
-
- for(int i = 0; i < searchPath.length; ++i) {
- String name = searchPath[i] + "." + editorName + "Editor";
-
- try {
- return instantiate(targetType, name);
- }
- }
-
- return null;
- }
- }
-
- public static String[] getEditorSearchPath() {
- return searchPath;
- }
-
- private static synchronized void initialize() {
- if (registry == null) {
- registry = new Hashtable();
- load(Byte.TYPE, "ByteEditor");
- load(Short.TYPE, "ShortEditor");
- load(Integer.TYPE, "IntEditor");
- load(Long.TYPE, "LongEditor");
- load(Boolean.TYPE, "BoolEditor");
- load(Float.TYPE, "FloatEditor");
- load(Double.TYPE, "DoubleEditor");
- }
- }
-
- private static PropertyEditor instantiate(Class sibling, String className) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
- ClassLoader cl = sibling.getClassLoader();
- if (cl != null) {
- try {
- Class cls = cl.loadClass(className);
- Object o = cls.newInstance();
- PropertyEditor ed = (PropertyEditor)o;
- return ed;
- } catch (Exception var6) {
- }
- }
-
- Class cls = Class.forName(className);
- Object o = cls.newInstance();
- PropertyEditor ed = (PropertyEditor)o;
- return ed;
- }
-
- private static void load(Class targetType, String name) {
- for(int i = 0; i < searchPath.length; ++i) {
- try {
- String editorName = searchPath[i] + "." + name;
- Class cls = Class.forName(editorName);
- registry.put(targetType, cls);
- return;
- }
- }
-
- System.err.println("load of " + name + " failed");
- }
-
- public static void registerEditor(Class targetType, Class editorClass) {
- initialize();
- if (editorClass == null) {
- registry.remove(targetType);
- } else {
- registry.put(targetType, editorClass);
- }
-
- }
-
- public static void setEditorSearchPath(String[] path) {
- if (path == null) {
- path = new String[0];
- }
-
- searchPath = path;
- }
- }
-